import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class code2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = in.next().toCharArray();
        int left = 0,right=0,n=s.length;
        int count = 0;//统计多少种字符
        int[] hash = new int[26];
        int ret = 0;

        while(right<n) {
            if(hash[s[right]-'a']++ == 0) count++;//0-1多了一种字符
            while(count>2) {
                if(hash[s[left++]-'a']--==1) {//1-0：少了一种字符
                    count--;
                }
            }
            ret = Math.max(ret,right-left+1);
            right++;
        }
        System.out.print(ret);
    }
}